package com.piano.web.controller.manage;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.piano.common.annotation.Log;
import com.piano.common.enums.BusinessType;
import com.piano.manage.domain.TIntention;
import com.piano.manage.service.ITIntentionService;
import com.piano.framework.web.base.BaseController;
import com.piano.common.page.TableDataInfo;
import com.piano.common.base.AjaxResult;
import com.piano.common.utils.poi.ExcelUtil;

/**
 * 意向学生 信息操作处理
 * 
 * @author pinao
 * @date 2019-02-25
 */
@Controller
@RequestMapping("/manage/tIntention")
public class TIntentionController extends BaseController
{
    private String prefix = "manage/tIntention";
	
	@Autowired
	private ITIntentionService tIntentionService;
	
	@RequiresPermissions("manage:tIntention:view")
	@GetMapping()
	public String tIntention()
	{
	    return prefix + "/tIntention";
	}
	
	/**
	 * 查询意向学生列表
	 */
	@RequiresPermissions("manage:tIntention:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TIntention tIntention)
	{
		startPage();
        List<TIntention> list = tIntentionService.selectTIntentionList(tIntention);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出意向学生列表
	 */
	@Log(title = "意向学生导出", businessType = BusinessType.EXPORT)
	@RequiresPermissions("manage:tIntention:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TIntention tIntention)
    {
    	List<TIntention> list = tIntentionService.selectTIntentionList(tIntention);
        ExcelUtil<TIntention> util = new ExcelUtil<TIntention>(TIntention.class);
        return util.exportExcel(list, "意向学生数据");
    }
	
	/**
	 * 新增意向学生
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存意向学生
	 */
	@RequiresPermissions("manage:tIntention:add")
	@Log(title = "意向学生", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TIntention tIntention)
	{		
		return toAjax(tIntentionService.insertTIntention(tIntention));
	}

	/**
	 * 修改意向学生
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		TIntention tIntention = tIntentionService.selectTIntentionById(id);
		mmap.put("tIntention", tIntention);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存意向学生
	 */
	@RequiresPermissions("manage:tIntention:edit")
	@Log(title = "意向学生", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TIntention tIntention)
	{		
		return toAjax(tIntentionService.updateTIntention(tIntention));
	}
	
	/**
	 * 删除意向学生
	 */
	@RequiresPermissions("manage:tIntention:remove")
	@Log(title = "意向学生", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tIntentionService.deleteTIntentionByIds(ids));
	}
	
}
